<template>
  <view class="login-container">
    <!-- 背景网格和故障效果 -->
    <view class="cyberpunk-grid"></view>
    <view class="glitch-overlay"></view>
    
    <!-- 标题区域 -->
    <view class="login-header">
      <view class="logo-container">
        <view class="logo-glitch"></view>
        <text class="app-title">通信质量智能诊断</text>
        <text class="app-subtitle">QUANTUM SIGNAL ANALYZER</text>
      </view>
    </view>
    
    <!-- 登录表单 -->
    <view class="login-form-container">
      <view class="login-form">
        <view class="form-title">
          <text class="title-text">系统登录</text>
          <text class="title-text-en">SYSTEM LOGIN</text>
        </view>
        
        <!-- 用户名输入框 -->
        <view class="input-group">
          <text class="input-label">用户名 / USERNAME</text>
          <view class="input-container">
            <text class="input-icon">👤</text>
            <input
              class="cyberpunk-input"
              type="text"
              v-model="formData.userName"
              placeholder="输入用户名"
            />
          </view>
        </view>
        
        <!-- 密码输入框 -->
        <view class="input-group">
          <text class="input-label">密码 / PASSWORD</text>
          <view class="input-container">
            <text class="input-icon">🔒</text>
            <input
              class="cyberpunk-input"
              type="password"
              v-model="formData.password"
              placeholder="输入密码"
            />
          </view>
        </view>
        
        <!-- 记住密码选项 -->
        <view class="options-row">
          <view class="remember-me">
            <checkbox 
              :checked="formData.rememberMe" 
              @tap="formData.rememberMe = !formData.rememberMe"
              class="cyberpunk-checkbox"
            />
            <text class="checkbox-text">记住密码</text>
          </view>
          <text class="forgot-password" @click="forgotPassword">忘记密码?</text>
        </view>
        
        <!-- 登录按钮 -->
        <view class="buttons-container">
          <button class="login-button" @click="handleLogin">
            <view class="button-content">
              <text class="button-text">登录系统</text>
              <!-- <text class="button-subtext">ACCESS GRANTED</text> -->
            </view>
          </button>
          <button class="register-button" @click="handleRegister">
            <view class="button-content">
              <text class="button-text">注册账号</text>
              <!-- <text class="button-subtext">NEW IDENTITY</text> -->
            </view>
          </button>
        </view>
      </view>
    </view>
    
    <!-- 底部信息 -->
    <view class="footer">
      <text class="footer-text">CYBERSIGNAL DIAGNOSTICS v2.0.77</text>
    </view>
  </view>
</template>

<script setup>
import { ref, reactive } from 'vue';
import http from '../../utils/http/http';
import userApi from '../../api/userApi';
// 表单数据
const formData = reactive({
  userName: '',
  password: '',
  rememberMe: false
});

// 登录处理函数
const handleLogin = () => {
  if (!formData.userName || !formData.password) {
    uni.showToast({
      title: '请输入用户名和密码',
      icon: 'none'
    });
    return;
  }
  
  userApi.login(formData).then(response =>{
	  console.log(response);
	  if (response.code=="200"){
		// 将当前用户保存到本地存储
		uni.setStorageSync('userInfo', response.data);
		  
	  	uni.switchTab({
	  	  url: '/pages/index/index' // 跳转到 tabbar 页面的路径
	  	});
	  }
	  else{
	  	uni.showToast({
	  	  title: "用户名密码错误",
	  	  icon: 'error'
	  	});
	  }
  }).catch(err =>{
	  console.log(err)
	  uni.showToast({
	  	title:"请求失败，请检查网络",
		icon:"none"
	  })
  })
  
  
}  

  

// 忘记密码处理函数
const forgotPassword = () => {
  uni.navigateTo({
    url: '/pages/forgot-password/forgot-password'
  });
};

// 注册处理函数
const handleRegister = () => {
  uni.navigateTo({
    url: '/pages/register/register'
  });
};

</script>

<style>
.login-container {
  position: relative;
  height: 100vh;
  width: 100%;
  background-color: #0a0a12;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* 赛博朋克网格背景 */
.cyberpunk-grid {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: 
    linear-gradient(rgba(18, 16, 37, 0.8) 1px, transparent 1px),
    linear-gradient(90deg, rgba(18, 16, 37, 0.8) 1px, transparent 1px);
  background-size: 20px 20px;
  background-position: center center;
  z-index: 1;
}

/* 故障效果叠加层 */
.glitch-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(45deg, 
    rgba(255, 0, 153, 0.1) 0%, 
    rgba(0, 255, 255, 0.1) 50%, 
    rgba(255, 0, 153, 0.1) 100%);
  z-index: 2;
  pointer-events: none;
}

/* 标题区域样式 */
.login-header {
  position: relative;
  z-index: 3;
  margin-bottom: 40px;
  text-align: center;
}

.logo-container {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.logo-glitch {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, #ff00cc, #3333ff);
  border-radius: 50%;
  margin-bottom: 15px;
  position: relative;
  box-shadow: 0 0 20px #ff00cc, 0 0 40px rgba(51, 51, 255, 0.5);
}

.logo-glitch::before {
  content: "";
  position: absolute;
  top: 5px;
  left: 5px;
  right: 5px;
  bottom: 5px;
  background: #0a0a12;
  border-radius: 50%;
  z-index: 1;
}

.logo-glitch::after {
  content: "";
  position: absolute;
  top: 15px;
  left: 15px;
  right: 15px;
  bottom: 15px;
  background: linear-gradient(135deg, #ff00cc, #3333ff);
  border-radius: 50%;
  z-index: 2;
  animation: pulse 4s infinite alternate;
}

.app-title {
  font-size: 28px;
  font-weight: bold;
  color: #ffffff;
  text-shadow: 0 0 10px #0ff, 0 0 20px #0ff;
  letter-spacing: 2px;
  margin-bottom: 5px;
}

.app-subtitle {
  font-size: 14px;
  color: #0ff;
  letter-spacing: 3px;
  text-transform: uppercase;
}

/* 登录表单容器 */
.login-form-container {
  position: relative;
  z-index: 3;
  width: 85%;
  max-width: 400px;
}

.login-form {
  background: rgba(15, 15, 25, 0.7);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 255, 255, 0.3);
  border-radius: 10px;
  padding: 30px;
  box-shadow: 0 0 20px rgba(0, 255, 255, 0.2);
  position: relative;
}

.login-form::before {
  content: "";
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  background: linear-gradient(45deg, #ff00cc, #3333ff, #0ff, #ff00cc);
  z-index: -1;
  border-radius: 12px;
  animation: borderGlow 10s linear infinite;
  opacity: 0.7;
}

.form-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 25px;
}

.title-text {
  font-size: 22px;
  color: #ffffff;
  text-shadow: 0 0 8px #0ff;
  letter-spacing: 2px;
  font-weight: bold;
}

.title-text-en {
  font-size: 16px;
  color: #0ff;
  letter-spacing: 3px;
  margin-top: 5px;
}

/* 输入框组样式 */
.input-group {
  margin-bottom: 20px;
}

.input-label {
  display: block;
  color: #0ff;
  font-size: 14px;
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.input-container {
  position: relative;
  display: flex;
  align-items: center;
  background-color: rgba(20, 20, 35, 0.8);
  border: 1px solid #0ff;
  border-radius: 5px;
  height: 45px;
  overflow: hidden;
  box-shadow: 0 0 10px rgba(0, 255, 255, 0.3);
}

.input-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 45px;
  height: 45px;
  font-size: 18px;
  background: rgba(0, 255, 255, 0.1);
}

.cyberpunk-input {
  flex: 1;
  height: 45px;
  background: transparent;
  border: none;
  color: white;
  padding: 0 15px;
  font-size: 16px;
}

.cyberpunk-input::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

/* 选项行样式 */
.options-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
  padding: 0 5px;
}

.remember-me {
  display: flex;
  align-items: center;
}

.checkbox-text {
  color: #0ff;
  font-size: 14px;
  margin-left: 5px;
}

.cyberpunk-checkbox {
  transform: scale(0.8);
}

.forgot-password {
  color: #ff00cc;
  font-size: 14px;
  text-decoration: underline;
}

/* 登录按钮样式 */
.buttons-container {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.login-button {
  background: linear-gradient(90deg, #ff00cc, #3333ff);
  border: none;
  height: 50px;
  border-radius: 5px;
  color: white;
  font-weight: bold;
  letter-spacing: 1px;
  position: relative;
  overflow: hidden;
  padding: 0;
}

.login-button::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  animation: buttonGlow 3s infinite;
}

.register-button {
  background: transparent;
  border: 1px solid #0ff;
  height: 50px;
  border-radius: 5px;
  color: white;
  font-weight: bold;
  letter-spacing: 1px;
  position: relative;
  overflow: hidden;
  padding: 0;
}

.register-button:active {
  background: rgba(0, 255, 255, 0.2);
}

.button-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.button-text {
  font-size: 18px;
  text-align: center;
}

.button-subtext {
  font-size: 10px;
  opacity: 0.8;
  letter-spacing: 2px;
  text-align: center;
}

/* 底部信息 */
.footer {
  position: absolute;
  bottom: 20px;
  z-index: 3;
}

.footer-text {
  color: rgba(0, 255, 255, 0.5);
  font-size: 12px;
  letter-spacing: 2px;
}

/* 动画效果 */
@keyframes pulse {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.1); opacity: 1; }
}

@keyframes borderGlow {
  0% { background-position: 0% 0%; }
  100% { background-position: 300% 0%; }
}

@keyframes buttonGlow {
  0% { left: -100%; }
  100% { left: 100%; }
}
</style>